<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="输入你的名称" lay-reqtext="用户名不能为空" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required"  lay-reqtext="密码不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" name="type" placeholder="输入类型" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" placeholder="输入手机号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱号</label>
        <div class="layui-input-block">
            <input type="text" name="email" placeholder="输入邮箱号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    var tableUid = "";
    window.onload = function(){
        tableUid = window.location.href.substring(window.location.href.indexOf("=")+1);
        console.log("tableUid：" + tableUid)
    }
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var datas = JSON.stringify(data.field);
            var parses = JSON.parse(datas);
            ajaxUpdate(parses);
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            var index = layer.alert("成功", {
                title: '提交结果'
            }, function () {
                parent.location.reload()
                return true;
            });
            return false;
        });

        //Ajax
        function ajaxUpdate(data){
            console.log("data:" + JSON.stringify(data))
            $.ajax({
                url: "/administrator/update",
                data:{
                    uid: tableUid,
                    name: data.name,
                    password: data.password,
                    phone: data.phone,
                    email: data.email,
                    type: data.type,
                },
                method: "post",
                success : function(cgdata){
                    console.log(JSON.stringify(cgdata));
                }
            })
        }

    });
</script>
</body>
</html>